{	Problem: http://codeforces.ru/problemset/problem/46/B
	Verdict: Accepted

}
const tip:array[1..5] of string = ('S','M','L','XL','XXL');
var i,n,tp:integer; t:array[1..5] of integer; s:string;
begin
for i:=1 to 5 do read(t[i]);
readln(n);
for i:=1 to n do begin
  readln(s);
  if s='S' then tp:=1 else
  if s='M' then tp:=2 else
  if s='L' then tp:=3 else
  if s='XL' then tp:=4 else
  if s='XXL' then tp:=5;
  if t[tp]>0 then begin
    writeln(tip[tp]);
    dec(t[tp]);
  end else
  if (tp<5) and (t[tp+1]>0) then begin
    writeln(tip[tp+1]);
    dec(t[tp+1]);
  end else
  if (tp>1) and (t[tp-1]>0) then begin
    writeln(tip[tp-1]);
    dec(t[tp-1]);
  end else
  if (tp<4) and (t[tp+2]>0) then begin
    writeln(tip[tp+2]);
    dec(t[tp+2]);
  end else
  if (tp>2) and (t[tp-2]>0) then begin
    writeln(tip[tp-2]);
    dec(t[tp-2]);
  end else
  if (tp<3) and (t[tp+3]>0) then begin
    writeln(tip[tp+3]);
    dec(t[tp+3]);
  end else
  if (tp>3) and (t[tp-3]>0) then begin
    writeln(tip[tp-3]);
    dec(t[tp-3]);
  end else
  if (tp<2) and (t[tp+4]>0) then begin
    writeln(tip[tp+4]);
    dec(t[tp+4]);
  end else
  if (tp>4) and (t[tp-4]>0) then begin
    writeln(tip[tp-4]);
    dec(t[tp-4]);
  end;
end;
readln;
end.